<?php

/**
 *
 *
 * @version $Id$
 * @copyright 2013
 */

namespace com\org\web\tpl\utils {
	class String {
		public static function isVarName($var) {
			return !self::isEmpty($var);
		}

		public static function isEmpty($name) {
			if (isset($name) && strlen(trim($name)) !== 0)
				return FALSE;
			return TRUE;
		}

		public static function startsWith($haystack, $needle, $case = TRUE) {
			if($case)
				return strpos($haystack, $needle, 0) === 0;
			return stripos($haystack, $needle, 0) === 0;
		}

		public static function endsWith($haystack, $needle, $case = TRUE) {
			$expectedPosition = strlen($haystack) - strlen($needle);
			if($case)
				return strrpos($haystack, $needle, 0) === $expectedPosition;
			return strripos($haystack, $needle, 0) === $expectedPosition;
		}

		public static function evalBool($bool) {
			if (is_bool($bool))
				return $bool;
			if (isset($bool) && (strcasecmp($bool, "true") === 0 || strcmp($bool, "1") === 0 || strcasecmp($bool, "yes") === 0 ||
				strcasecmp($bool, "y") === 0))
				return TRUE;
			return FALSE;
		}

		public static function trim($array, $charList = NULL) {
			$count = count($array);
			for($i = 0; $i < $count; $i++)
				$array[$i] = trim($array[$i], $charList);
			return $array;
		}
	}
}
?>